package com.rt.easyjava.common.utils.others;

import java.io.*;

public class FileUtils {

	public static boolean isExist(String path) {
		File file = new File(path);
		return file.exists();
	}

	public static void AppendContent(String fileDir, String fileName,
			String content) {
		File file = new File(fileDir + fileName);
		if (!file.exists()) {
			file.getParentFile().mkdirs();
			BufferedWriter out = null;
			try {
				out = new BufferedWriter(new OutputStreamWriter(
						new FileOutputStream(file, false)));
				out.write(content + "\r\n");
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				try {
					if (out != null) {
						out.close();
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} else {
			BufferedWriter out = null;
			try {
				out = new BufferedWriter(new OutputStreamWriter(
						new FileOutputStream(file, true)));
				out.write(content + "\r\n");
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				try {
					if (out != null) {
						out.close();
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void main(String[] args) throws Exception {
		FileUtils.AppendContent("d:/TradeLog/", "test.txt", "testContant");

	}
}
